import 'package:flutter/widgets.dart';
import 'package:pp_uikit/pp_uikit_constants.dart';
import 'package:pp_uikit/theme/pp_group_theme.dart';

class PPGroupUtil {
  /// 获取必填项
  static Widget buildRequireWidget(bool isRequire) {
    return Offstage(
      offstage: (!isRequire),
      child: Container(
        padding: isRequire
            ? const EdgeInsets.only(right: 2)
            : const EdgeInsets.only(right: 0),
        child: isRequire
            ? Image.asset(
                "images/icon_require_red.png",
                width: 8,
                height: 8,
                color: const Color(0xFFFA3F3F),
                package: PPUIKitConstant.packageName,
              )
            : null,
      ),
    );
  }

  static Widget buildTitleWidget(String? title, {TextStyle? style}) {
    return Text(
      title ?? "",
      style: style ?? PPGroupTheme().titleTextStyle,
    );
  }

  static Widget buildSubLabelWidget(String? title) {
    return Expanded(
        flex: 1,
        child: Offstage(
          offstage: title == null,
          child: Text(
            title ?? "",
            textAlign: TextAlign.right,
            style: PPGroupTheme().subTitleTextStyle,
          ),
        ));
  }

  /// 获取右边Icon
  static Widget buildRightIconWidget(bool isShow,
      {PPGroupArrawDirection arrawDirection = PPGroupArrawDirection.right}) {
    Image? iconImage;
    if (isShow) {
      iconImage = arrawDirection == PPGroupArrawDirection.right
          ? Image.asset(
              "images/icon_arrow_right_black.png",
              width: 14,
              height: 14,
              color: const Color(0xFF999999),
              package: PPUIKitConstant.packageName,
            )
          : Image.asset(
              "images/icon_arrow_bottom_black.png",
              width: 14,
              height: 14,
              color: const Color(0xFF999999),
              package: PPUIKitConstant.packageName,
            );
    }
    return Offstage(
      offstage: (!isShow),
      child: Container(
        padding: isShow
            ? const EdgeInsets.only(left: 4)
            : const EdgeInsets.only(right: 0),
        child: iconImage,
      ),
    );
  }

  /// 获取是否可编辑的字体
  static TextStyle getEditTextStyle(bool isEdit) {
    PPGroupTheme themeData = PPGroupTheme();
    return isEdit ? themeData.contentTextStyle : themeData.disableTextStyle;
  }
}
